home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / The Hacks! / Talking KeyBoard / Source / AppleEvents / aecoercions.c < prev    next >
Encoding:
Text File  |  1998-05-08  |  1.9 KB  |  57 lines  |  [TEXT/CWIE]

  1. // Program Author: Paul Baxter
  2. //    pbaxter@assistivetech.com
  3. //
  4. //
  5.  
  6.  
  7. #include "aeutils.h"
  8. #include "aetoken.h"
  9. #include "aeaccessors.h"
  10. #include "aecoercions.h"
  11.  
  12. // * ****************************************************************************** *
  13. // *            InstallCoercions
  14. // *                                Install AppleEvent Coercions 
  15. // * ****************************************************************************** *
  16. OSErr    InstallCoercions(void)
  17. {
  18.     OSErr    err;
  19.  
  20.      err = AEInstallCoercionHandler(typeObjectSpecifier, typeNull,        (AECoercionHandlerUPP)NewAECoerceDescProc(CoerceObjToAnything), 0, true, false);
  21.        err = AEInstallCoercionHandler(typeObjectSpecifier, typeMyApplProp,  (AECoercionHandlerUPP)NewAECoerceDescProc(CoerceObjToAnything), 0, true, false);
  22.      err = AEInstallCoercionHandler(typeObjectSpecifier, typeMyAppl,      (AECoercionHandlerUPP)NewAECoerceDescProc(CoerceObjToAnything), 0, true, false);
  23.     return(err);
  24. }
  25.  
  26. // * ****************************************************************************** *
  27. // *            CoerceObjToAnything
  28. // *                Takes an object specifier that it resolves using AEResolve
  29. // *                then tries to coerce this result into the type specified by toType
  30. // * ****************************************************************************** *
  31. pascal OSErr CoerceObjToAnything(const AEDesc    *theAEDesc,
  32.                                     DescType        toType,
  33.                                     long            handlerRefCon,
  34.                                     AEDesc            *result)
  35. {
  36. #pragma unused (handlerRefCon)
  37.  
  38.     AEDesc     objDesc = {typeNull, NULL};
  39.     OSErr      err;    
  40.  
  41.     if (theAEDesc->descriptorType != typeObjectSpecifier)
  42.         return(errAEWrongDataType);
  43.     
  44.         // resolve the object specifier
  45.     err = AEResolve(theAEDesc, kAEIDoMinimum, &objDesc);
  46.     if (noErr != err) goto done;
  47.         
  48.         // hopefully it's the right type by now, but we'll give it a nudge
  49.     err = AECoerceDesc(&objDesc, toType, result);
  50.  
  51. done:
  52.     if (objDesc.dataHandle)
  53.         AEDisposeDesc(&objDesc);
  54.             
  55.     return(err);
  56. }    // CoerceObjToAnything
  57.